<?php

namespace App\Http\Logic;

use App;
use App\Common\Status;
use App\Helper\Helper;
use Illuminate\Support\Facades\DB;

trait NoteOtherLogic
{

    /**
     * @param $mobile string
     * @return array
     */
    public static function GetAnnex(string $mobile): array
    {
        $annex = DB::table("recruit_notes_middle as a")
            ->join("recruit_resources as b", "a.res_id", "=", "b.id")
            ->select(["b.path","b.id","a.att_name","a.created_at"])
            ->where([
                ['a.mobile', "=", $mobile], ['a.status', "=", Status::UNKNOWN], [
                    'a.is_deleted', "=",
                    Status::NOT_DELETE
                ]
            ])->first();
        if ($annex) {
            $path = Helper::buildQiNiuUrl($annex->path);
            return ["id"=>$annex->id,"name"=>$annex->att_name,"path"=>$path,"created_at"=>$annex->created_at];
        }
        return [];
    }

    /**
     * @param $headImgId int
     * @return string
     */
    public static function GetUserHeard(int $headImgId): string
    {
        $path     = "";
        $userInfo = DB::table("recruit_resources")->select("path")->where('id', $headImgId)
            ->first();
        if ($userInfo) {
            $path = Helper::buildQiNiuUrl($userInfo->path);
        }
        return $path;
    }
}
